package com.jyniubi.core.controller.api;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jyniubi.base.result.R;
import com.jyniubi.core.pojo.entity.LendReturn;
import com.jyniubi.core.service.LendReturnService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 还款记录表 前端控制器
 * </p>
 *
 * @author jyzhang
 * @since 2024-04-27
 */
@RestController
@RequestMapping("/api/core/lendReturn")
public class ApiLendReturnController {
    @Resource
    private LendReturnService lendReturnService;

    @ApiOperation("还款回调")
    @PostMapping("/notifyUrl")
    public String  notifyUrl(HttpServletRequest request){
        String result = lendReturnService.notifyUrl(request);
        return result;
    }

    @ApiOperation("还款")
    @GetMapping("/borrowReturn/{lendReturnId}")
    public R borrowReturn(@PathVariable("lendReturnId")String lendReturnId,
                          @RequestHeader(value = "token",required = false)String token){
        String form = lendReturnService.borrowReturn(lendReturnId,token);
        return R.ok().data("form",form);
    }
    @ApiOperation("标的还款记录")
    @GetMapping("/getLendReturnList/{lendId}")
    public R getLendReturnList(@PathVariable("lendId")String lendId){
        return R.ok().data("items",lendReturnService.list(Wrappers.lambdaQuery(LendReturn.class)
                .eq(LendReturn::getLendId,lendId)));
    }
}

